package com.minhua.jijiehao2.mainframe.circle.entryActivity.impl

import android.content.Intent
import com.minhua.jijiehao2.R
import com.minhua.jijiehao2.base.BaseActivity
import com.minhua.jijiehao2.bean.CompanyIdentifyBean
import com.minhua.jijiehao2.mainframe.circle.companyIdentifyActivity.impl.CompanyIdentifyActivity
import com.minhua.jijiehao2.mainframe.circle.entryActivity.imp.IEntryView
import com.minhua.jijiehao2.mainframe.launcher.loginactivity.impl.LoginActivity
import com.minhua.jijiehao2.mainframe.mine.companyResultActivity.impl.CompanyResultActivity
import kotlinx.android.synthetic.main.activity_entry.*

class EntryActivity : BaseActivity<IEntryView, EntryPresenter>(), IEntryView {

    override fun getLayoutId(): Int = R.layout.activity_entry

    override fun getPresenter(): EntryPresenter = EntryPresenter()

    override fun initView() {
        tvEntry.setOnClickListener {
            if (LoginActivity.logged(this)) {
                when (status) {
                    0 -> startActivity(Intent(this, CompanyIdentifyActivity::class.java))
                    1, 2, 3 -> {
                        companyIdentifyBean?.auditState = 2
                        CompanyResultActivity.intentStart(this, companyIdentifyBean)
                    }
                }
            }
        }
    }

    private var status = 0
    private var companyIdentifyBean: CompanyIdentifyBean? = null
    override fun onStatusSuccess(companyIdentifyBean: CompanyIdentifyBean) {
        this.companyIdentifyBean = companyIdentifyBean
        status = companyIdentifyBean.auditState
        when (status) {
            1 -> tvEntry.text = "查看进度"
            2, 3 -> tvEntry.text = "查看产品"
            else -> tvEntry.text = "立即入驻"
        }
    }

    override fun onResume() {
        super.onResume()
        mPresenter.getIdentifyStatus()
    }
}
